import { getPage } from '../../utils/config';
import api from '../../utils/api';
import wxApi from '../../utils/wxApi';
import { http, $loading, $toast } from '../../utils/utils';
const app = getApp();

Page({

    /**
     * 页面的初始数据
     */
    data: {
        loading: 0,
        expressInfo: {},
    },

    /**
     * 联系客服
     */
    callPhoneClick() {
        const { expressInfo } = this.data;
        wx.makePhoneCall({
            phoneNumber: expressInfo.info.Tel
        });
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {

        //判断是否携带参数
        if (options && JSON.stringify(options) !== '{}'){
            this.setData({
                tracknum: options.tracknum,
                shippingName: options.shippingName,
                orderId: options.orderId,
                shipping: options.shipping,
            });
        }

        //判断是否登录
        app.getLogin().then((res) => {
            const { user } = res.data;
            this.setData({
                logged: res.code,
                userId: user.user_id,
                userRank:user.user_rank,
            });
            
            const { tracknum, shippingName, orderId, shipping } = this.data;
            http.post(api.default, {
                data: {
                    action: 'express_detail',
                    tracknum: tracknum,
                    shipping_name: shippingName,
                    orderid: orderId,
                    shipping: shipping,
                }
            }, false).then((res) => {
                const { data } = res.data;
                this.setData({
                    expressInfo: data,
                    loading: 1,
                });
            });
        });
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {
        
    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    }
})